﻿using AutoMapper;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ZFB.Common;
using ZFB.DTO;
using ZFB.IServices;
using ZFB.Repository.AdminUser;
using ZFB.Repository.Community;

namespace ZFB.Services
{
    public class CommunityServices : ICommunityServices
    {
        private readonly ICommunityRepository  communityRepository;
        private readonly IMapper mapper;
        public CommunityServices(ICommunityRepository communityRepository, IMapper mapper)
        {
            this.communityRepository = communityRepository;
            this.mapper = mapper;
        }

        public async Task<ApiResult> GetByRegionIdAsync(long regionId)
        {
            var data = await communityRepository.GetListAsync(e =>e.RegionId == regionId);
            if (data==null)
            {
                return new ApiResult("获取失败!");
            }
            else
            {
                var dto = mapper.Map<List<CommunityDTO>>(data);
                return new ApiResult(dto);
            }
        }
    }
}
